define(function(require, exports, module) {

    var rk = require('rk');

    // require('commonjs');







    var currentPageUserId = SESSION.user.id;


    $.widget('rk.scheduleFinalCtrl', {
        options: {
            scheduleId: null
        },
        _create: function() {
            var me = this,
                elem = this.element,
                opt = this.options;
            if (opt.scheduleId && /^\d+$/.test(opt.scheduleId)) {
                $.getJSON('/json/crm_schedule/detail.action?scheduleId=' + opt.scheduleId, function(json) {
                    if (json.status == '0') {
                        if (json.data.schedule.accessible) {
                            me.showDetail(json.data);
                            me.addHandlers(json.data);
                        } else {
                            //elem.html('<div class="content_error"><p>您没有权限查看该日程</p></div>');
                            elem.html('<div class="helpful_box"><div class="helpful_content">' + rk.i18n('SCHEDULE_18') + '</div></div>');
                        }
                    } else if (json.status == '300002') {
                        //elem.html('<div class="content_error"><p>该日程已被删除或退出</p></div>');
                        elem.html('<div class="helpful_box"><div class="helpful_content">' + rk.i18n('SCHEDULE_19') + '</div></div>');
                    } else if (json.status == '300001') {
                        //elem.html('<div class="content_error"><p>您没有权限查看该日程</p></div>');
                        elem.html('<div class="helpful_box"><div class="helpful_content">' + rk.i18n('SCHEDULE_18') + '</div></div>');
                    } else {
                        $.msg(rk.i18n('SCHEDULE_20') + json.statusText);
                    }
                });
            }
        },
        showDetail: function(data) {
            var me = this,
                elem = this.element,
                opt = this.options;
            var schedule = data.schedule;

            schedule.hasDelete = +currentPageUserId == schedule.createdBy ? '<a class="delete" schedulename="' + schedule.name + '">' + rk.i18n('SCRPT_TMPL_SCHEDULE_DETAIL_1') + '</a>' : ~$.inArray(+currentPageUserId, data.acceptMember) ? '<a class="exit quit" schedulename="' + schedule.name + '">' + rk.i18n('SCHEDULE_QUIT_THIS') + '</a>' : '';
            //schedule.hasModify = +currentPageUserId == schedule.createdBy || ~$.inArray(+currentPageUserId, data.acceptMember) ? '<a class="modify">修改日程</a>' : '';
            schedule.canModify = currentPageUserId == schedule.createdBy || ~$.inArray(+currentPageUserId, data.acceptMember);

            var isWaiting = $.inArray(SESSION.user.id, data.waitingMember) > -1;
            var isAccept = $.inArray(SESSION.user.id, data.acceptMember) > -1;
            var isReject = $.inArray(SESSION.user.id, data.rejectMember) > -1;
            //schedule.powerExit = isAccept ? '' : 'hidden';
            schedule.powerExit = isAccept;
            if (currentPageUserId == schedule.createdBy)
                schedule.powerExit = false;
            schedule.creater = data.users[schedule.createdBy].name;
            schedule.createdDate = Globalize.format(new Date(schedule.createdAt - 0), 'yyyy-MM-dd');
            schedule.createdTime = Globalize.format(new Date(schedule.createdAt - 0), 'HH:mm');

            schedule.duration = $.map((function() {
                var sd = Globalize.format(new Date(schedule.startDate - 0), 'yyyy-MM-dd'),
                    st = Globalize.format(new Date(schedule.startDate - 0), 'HH:mm');
                ed = Globalize.format(new Date(schedule.endDate - 0), 'yyyy-MM-dd');
                et = Globalize.format(new Date(schedule.endDate - 0), 'HH:mm');
                if (schedule.isAllDay == '1') {
                    if (sd == ed) {
                        return [sd];
                    } else {
                        return [sd, rk.i18n('TO'), ed];
                    }
                } else {
                    if (sd == ed) {
                        if (st == et) {
                            return [sd, st];
                        } else {
                            return [sd, st, rk.i18n('TO'), et];
                        }
                    } else {
                        return [sd, st, rk.i18n('TO'), ed, et];
                    }
                }
            })(), function(s) {
                return '<span>' + s + '</span>';
            }).join('');

            schedule.rptinfo = (function(o) {
                if (o.isRecur == '1') {
                    return '<div class="schedule_field relation_field"><div class="field_name"></div><div class="field_content"><div class="tixin">' +
                        $.map([
                            ['', rk.i18n('SCHEDULE_25'), rk.i18n('SCHEDULE_26'), rk.i18n('SCHEDULE_27')][o.frequency], rk.i18n('SCHEDULE_REPEAT'), ',',
                            o.recurStopCondition == '1' ? rk.i18n('SCHEDULE_NO_END') : (rk.i18n('SCHEDULE_54') + $.datepicker.formatDate('yy-mm-dd', new Date(+o.recurStopValue)) + rk.i18n('SCHEDULE_55'))
                        ], function(str) {
                            return str ? '<span>' + str + '</span>' : null;
                        }).join('') + '</div></div></div>';
                } else {
                    return '';
                }
            })(schedule);

            schedule.remind = {
                '-1': rk.i18n('SCHEDULE_NO_REMIND'),
                '0': rk.i18n('SCHEDULE_IN_TIME'),
                '600': rk.i18n('SCHEDULE_EARLY_10MINUTE'),
                '1800': rk.i18n('SCHEDULE_EARLY_30MINUTE'),
                '3600': rk.i18n('SCHEDULE_EARLY_1HOUR'),
                '7200': rk.i18n('SCHEDULE_EARLY_2HOUR'),
                '21600': rk.i18n('SCHEDULE_EARLY_6HOUR'),
                '86400': rk.i18n('SCHEDULE_EARLY_1DAY'),
                '54000': rk.i18n('SCHEDULE_9_INDAY'),
                '-32400': rk.i18n('SCHEDULE_9_BEFOREDAY')
            }[schedule.reminder];

            schedule.acceptMember = $.map(data.acceptMember || [], function(uid) {
                return '<li><a href="/final/user.action?uid=' + uid + '" title="' + $.htmlEncode(data.users[uid].name) + '"><img ucard="uid=' + uid + '" src="' + (data.users[uid].icon || DEFAULTS.USER_DEFAULT_ICON) + '"/></a></li>';
            }).join('');
            if (schedule.acceptMember) {
                schedule.members = '<ul class="task_people_list">' + schedule.acceptMember + '</ul>';
            }
            schedule.waitingMember = $.map(data.waitingMember || [], function(uid) {
                return '<li><a href="/final/user.action?uid=' + uid + '" title="' + $.htmlEncode(data.users[uid].name) + '"><img ucard="uid=' + uid + '" src="' + (data.users[uid].icon || DEFAULTS.USER_DEFAULT_ICON) + '"/></a></li>';
            }).join('');
            if (schedule.waitingMember) {
                schedule.waiting = '<div class="confirmed_people participants"><span class="tip">' + rk.i18n('SCHEDULE_28') + '</span><ul class="task_people_list">' + schedule.waitingMember + '</ul></div>';
            }
            schedule.rejectMember = $.map(data.rejectMember || [], function(uid) {
                return '<li><a href="/final/user.action?uid=' + uid + '" title="' + $.htmlEncode(data.users[uid].name) + '"><img ucard="uid=' + uid + '" src="' + (data.users[uid].icon || DEFAULTS.USER_DEFAULT_ICON) + '"/></a></li>';
            }).join('');
            if (schedule.rejectMember) {
                schedule.reject = '<div class="confirmed_people participants"><span class="tip">' + rk.i18n('SCHEDULE_29') + '</span><ul class="task_people_list">' + schedule.rejectMember + '</ul></div>';
            }
            if (schedule.description) {
                //schedule.description = '<div id="task_description_label" class="task_description schedule_task_description"><span class="task_list_noneinfo">' + schedule.description + '</span></div>';
                schedule.description = $.htmlEncode(schedule.description).replace(/\n/g, '<br>');
            } else {
                schedule.description = rk.i18n('NO_DESCRIPTION');
            }

            if (schedule.objectId) {
                schedule.relation = (function(o) {
                    var entry = data.sourceEntity,
                        rMap = {
                            1: {
                                name: SESSION.keywords.account,
                                url: '/final/account.action?id=',
                                cname: 'account'
                            },
                            3: {
                                name: SESSION.keywords.opportunity,
                                url: '/final/opportunity.action?id=',
                                cname: 'opportunity'
                            },
                            2: {
                                name: SESSION.keywords.contract,
                                url: '/final/contact.action?id=',
                                cname: 'contact'
                            },
                            6: {
                                name: SESSION.keywords.campaign,
                                url: '/final/campaign.action?id=',
                                cname: 'campaign'
                            },
                            11: {
                                name: SESSION.keywords.lead,
                                url: '/final/lead.action?id=',
                                cname: 'leads'
                            },
                            66: {
                                name: SESSION.keywords.agent,
                                url: '/final/agent.action?id=',
                                cname: 'terminal'
                            },
                            67: {
                                name: SESSION.keywords.terminal,
                                url: '/final/terminal.action?id=',
                                cname: 'terminal'
                            }
                        };
                    return ['<div class="schedule_field relation_field"><div class="field_name">' + rk.i18n('SCHEDULE_RELATE_BUSINESS') + '</div><div class="field_content"><div class="show_ralation_bussiness"><span class="task_group"><p class="feed-group-name"><span class="feed-group-class ', rMap[o.belongId].cname, '"></span><a title="' + rk.i18n('SCHEDULE_24') + '：', rMap[o.belongId].name, '" href="', rMap[o.belongId].url + entry.id, '">', entry.name, '</a></p></span></div></div></div>'].join('');
                })(schedule);
            }

            schedule.files = data.files.length;

            var tplTabs = require('oa/tmpl/schedule/tpl_schedule_final.tpl');
            var html = rk.templateText(tplTabs, data);
            elem.html(html);

            var acceptHeadOper = elem.find("div[act=schedule_operat_area]").eq(0);
            var quitDelBtn = elem.find("div[act=schedule_detail_head]").eq(0);
            //缺省隐藏接受、拒绝按钮
            quitDelBtn.show();
            //如果不在接受组里，说明是退出了
            if (!isAccept) {
                //初始态
                if (isWaiting) {
                    acceptHeadOper.show();
                    quitDelBtn.hide();
                } else {
                    //隐藏两排按钮
                    acceptHeadOper.hide();
                    //quitDelBtn.hide();
                }
            } else {
                //已接受
                if (!isWaiting) {
                    acceptHeadOper.hide();
                    //quitDelBtn.show();
                }

                //拒绝态，头隐藏
                if (isReject) {
                    acceptHeadOper.hide();
                    quitDelBtn.hide();
                }
            }
        },
        addHandlers: function(data) {
            var me = this,
                elem = this.element,
                opt = this.options;

            //接受日程
            elem.find('#btnAcceptSchedule').on('click', function(evt) {
                evt.preventDefault();
                $.post('/json/crm_schedule/accept.action', {
                    scheduleId: opt.scheduleId
                }, null, 'json').done(function(json) {
                    if (json.status == 0) {
                        //rk.oa.closeContent();
                        /*rk.oa.popupCurtain({
                            onSuccess: function(curtainElem) {
                                curtainElem.scheduleCurtainCtrl({
                                    aType: 'toMe',
                                    viewType: null
                                });
                            }
                        });*/
                        $.msg(rk.i18n('SCHEDULE_34'), 1);
                        //退出、编辑按钮显示
                        elem.find("div[act=schedule_operat_area]").eq(0).hide();
                        elem.find("div[act=schedule_detail_head]").eq(0).show();
                        rk.oa.closeContent();
                    } else {
                        $.msg(rk.i18n('SCHEDULE_35'));
                    }
                }).fail(function(def, code, message) {
                    def.status != 0 && $.msg(rk.i18n('REQUEST_ERROR'));
                });
            });

            //拒绝日程
            elem.find('#btnRejectSchedule').on('click', function(evt) {
                evt.preventDefault();
                $('#rejectScheduleDiv').show();
            });
            elem.find('#btnRejectSubmit').on('click', function(evt) {
                evt.preventDefault();
                var content = $.trim($("#rejectScheduleInput").val());
                var fromPage = $("#fromPage_update").val();
                if (content.length > 0) {
                    if (content.length > 100) {
                        $("#rejectScheduleInput").focus();
                        $.msg(rk.i18n('TASK_REJECT_NOT_MORE_THAN'));
                        return false;
                    }
                    $.post('/json/crm_schedule/reject.action', {
                        scheduleId: opt.scheduleId,
                        content: content
                    }, null, 'json').done(function(json) {
                        if (json.status == 0) {
                            rk.oa.closeContent();
                            rk.oa.popupCurtain({
                                onSuccess: function(curtainElem) {
                                    curtainElem.scheduleCurtainCtrl({
                                        aType: 'toMe',
                                        viewType: null
                                    });
                                }
                            });
                            $.msg(rk.i18n('SCHEDULE_36'), 1);
                            //退出、编辑按钮显示
                            elem.find("div[act=schedule_detail_head]").eq(0).hide();
                            elem.find("div[act=schedule_operat_area]").eq(0).hide();
                            elem.find("div[act=schedule_detail_head]").eq(0).hide();
                        } else {
                            $.msg(rk.i18n('SCHEDULE_37'));
                        }
                    });
                } else {
                    $.msg(rk.i18n('TASK_CONTENT_DETAIL_4'))
                }
            });

            //删除日程
            elem.find('a.delete').on('click', function(evt) {
                evt.preventDefault();
                var sname = $(this).attr('schedulename');
                rk.confirm(rk.i18n('SCHEDULE_38', sname), function() {
                    $.post('/json/crm_schedule/delete.action', {
                        scheduleId: opt.scheduleId
                    }, null, 'json').done(function(json) {
                        if (json.status == 0) {
                            $.msg(rk.i18n('SCHEDULE_39'));
                        } else {
                            $.msg(rk.i18n('SCHEDULE_40'));
                        }
                    });
                });
            });

            //退出日程
            elem.find('a.js-exit').on('click', function(evt) {
                evt.preventDefault();
                var sname = $(this).attr('schedulename');
                rk.confirm(rk.i18n('SCHEDULE_41', sname), function() {
                    $.post('/json/crm_schedule/quit.action', {
                        scheduleId: opt.scheduleId
                    }, null, 'json').done(function(json) {
                        if (json.status == 0) {
                            //elem.taskList();
                            //$detail.remove();
                            $('div[_scheduleId=' + opt.scheduleId + ']').remove();
                            rk.oa.closeContent();
                            $.msg(rk.i18n('SCHEDULE_42'), 1);

                            //重刷当前页面
                            window.location.href = '/final/schedule.action?scheduleId=' + encodeURIComponent(opt.scheduleId);
                        } else {
                            $.msg(rk.i18n('SCHEDULE_43'));
                        }
                    }).fail(function(def, code, message) {
                        def.status != 0 && $.msg(rk.i18n('REQUEST_ERROR'));
                    });
                });
            });

            //修改日程
            elem.find('a.modify').on('click', function(evt) {
                //elem.find('a[act=modify]').on('click', function(evt) {
                evt.preventDefault();
                var option = {
                    eventId: opt.scheduleId,
                    act: 'edit',
                    viewName: null,
                    eventType: 'schedule'
                };
                var scheduleUtil = require('oa/js/schedule/asset/utils/scheduleUtil');
                scheduleUtil.popupEditor(option);
            });



            var $liTabs = elem.find('ul.bottom_tabs li[type]');
            //var $divPanels = elem.find('div.bottom_tabs_content >div.nc_task_bottom_content');

            //$liTabs.on('click',
            var $divPanels = elem.find("div[act=tab_content]");
            elem.on('click', '[act="bottom_tab"]', function(evt) {
                var $tab = $(this);
                if (!$tab.hasClass('hover')) {
                    $liTabs.removeClass('hover');
                    $divPanels.hide();
                    var index = $liTabs.index(this),
                        $panel = $divPanels.eq(index);
                    $tab.addClass('hover');
                    $panel.show('fade', 'fast');
                    if (!$tab.data('inited')) {
                        if (index == 0) {
                            $panel.find('.js-comments').comment({
                                previewList: data.comments, //预展示列表
                                totalCount: data.commentCount, //总条数
                                systemId: 608,
                                systemItemId: opt.scheduleId,
                                allusers: data.users //若有previewList,需要把对应的user对象放进来
                            });
                        } else if (index == 1) {
                            if (data.files.length) {
                                $.each(data.files, function(_, file) {
                                    me.appendNimei($panel, $.extend({
                                        createdByName: data.users[file.createdBy].name,
                                        createAtFmt: Globalize.format(new Date(file.createdAt - 0), 'yyyy-MM-dd HH:mm')
                                    }, file));
                                });
                            }
                            $panel.addClass('js-album-box').album({
                                selector: 'img.js-album'
                            });
                            $panel.on('click', '.js-file-previewable', function(evt) {
                                var $lnk = $(this),
                                    filename = $lnk.attr('filename'),
                                    swfpath = $lnk.attr('swfpath');
                                var $dialog = $('<div style="overflow: hidden;"></div>'),
                                    id = $dialog.uniqueId().attr('id');
                                $dialog.popup({
                                    width: 700,
                                    height: 600,
                                    title: rk.i18n('TASK_VIEW_FILE') + filename,
                                    resizable: true,
                                    open: function() {
                                        var flashvars = {
                                            SwfFile: escape(swfpath),
                                            Scale: 0.6,
                                            ZoomTransition: "easeOut",
                                            ZoomTime: 0.5,
                                            ZoomInterval: 0.1,
                                            FitPageOnLoad: false,
                                            FitWidthOnLoad: true,
                                            PrintEnabled: true,
                                            FullScreenAsMaxWindow: false,
                                            ProgressiveLoading: true,

                                            PrintToolsVisible: true,
                                            ViewModeToolsVisible: true,
                                            ZoomToolsVisible: true,
                                            FullScreenVisible: true,
                                            NavToolsVisible: true,
                                            CursorToolsVisible: true,
                                            SearchToolsVisible: true,
                                            localeChain: "zh_CN"
                                        };
                                        new FlexPaperViewer(SESSION.resDomain + '/static/swf/flexpager.swf', id, {
                                            config: flashvars
                                        });
                                    }
                                });
                            });
                            $panel.on('click', 'a[act="delete"]', function(evt) {
                                evt.preventDefault();
                                var $lnk = $(this);
                                rk.confirm(rk.i18n('TASK_CONFIRM_DELETE_FILE'), function() {
                                    $.postJson('/json/crm_schedule/delete-file.action', {
                                        fileId: $lnk.attr('fileId')
                                    }).done(function(json) {
                                        if (json.status == 0) {
                                            $.msg(rk.i18n('TASK_DELETE_SUCCESS'), 1);
                                            $lnk.parents('div.detail_attachment').remove();
                                        } else {
                                            $.msg(rk.i18n('TASK_DELETE_ERROR'));
                                        }
                                    }).fail(function(def, code, message) {
                                        def.status != 0 && $.msg(rk.i18n('REQUEST_ERROR'));
                                    });
                                });
                            });
                            var queueId = $panel.find('div.js-upd-queue').uniqueId().attr('id');

                            var $picUploadBtn = $panel.find('input.pic_attachment');
                            $picUploadBtn.uniqueId();
                            $picUploadBtn.uploadMultiImage({
                                uploader: '/json/global_uploadify/schedule-upload.action',
                                buttonText: rk.i18n('TASK_UPLOAD_IMG'),
                                buttonClass: 'pic_attachment',
                                queueID: queueId,
                                removeCompleted: true,
                                removeTimeout: 0,
                                onUploadSuccess: function(file, data, response) {
                                    var json = $.parseJSON(data);
                                    if (json.status == 0) {
                                        me.appendImage($panel, $.extend({
                                            createdByName: SESSION.user.name,
                                            createAtFmt: Globalize.format(new Date(), 'yyyy-MM-dd HH:mm')
                                        }, json.data.file));
                                    }
                                },
                                onUploadStart: function(file) {
                                    $picUploadBtn.uploadify('settings', 'formData', {
                                        'pageTenantId': SESSION.tenantId,
                                        'uploadFileName': file.name,
                                        'pageUserId': SESSION.user.id,
                                        'systemItemId': opt.scheduleId
                                    });
                                }
                            });
                            var $fileUploadBtn = $panel.find('input.file_attachment');
                            $fileUploadBtn.uniqueId();
                            $fileUploadBtn.uploadMultiFile({
                                uploader: '/json/global_uploadify/schedule-upload.action',
                                buttonText: rk.i18n('TASK_UPLOAD_FILE'),
                                buttonClass: 'file_attachment',
                                queueID: queueId,
                                removeCompleted: true,
                                removeTimeout: 0,
                                onUploadSuccess: function(file, data, response) {
                                    var json = $.parseJSON(data);
                                    if (json.status == 0) {
                                        me.appendFile($panel, $.extend({
                                            createdByName: SESSION.user.name,
                                            createAtFmt: Globalize.format(new Date(), 'yyyy-MM-dd HH:mm')
                                        }, json.data.file));
                                    }
                                },
                                onUploadStart: function(file) {
                                    $fileUploadBtn.uploadify('settings', 'formData', {
                                        'pageTenantId': SESSION.tenantId,
                                        'uploadFileName': file.name,
                                        'pageUserId': SESSION.user.id,
                                        'systemItemId': opt.scheduleId
                                    });
                                }
                            });

                        } else if (index == 2) {
                            $.getJSON('/json/crm_schedule/logs.action?scheduleId=' + opt.scheduleId).done(function(json) {
                                if (json.status == 0) {
                                    var data = json.data,
                                        logs = data.logList;
                                    var html = $.map(logs, function(log) {
                                        var opid = log.userId,
                                            opname = data.users[opid].name,
                                            opicon = data.users[opid].icon || DEFAULTS.USER_DEFAULT_ICON,
                                            msg = '';
                                        var content = $.parseJSON(log.content);
                                        switch (log.operType) {
                                            case 1:
                                                //CREATE
                                                msg = rk.i18n('SCHEDULE_44');
                                                break;
                                            case 2:
                                                //UPDATE
                                                if (log.target == 'schedule.label.name') {
                                                    msg = [rk.i18n('SCHEDULE_45') + '【', content.sourceContent, '】' + rk.i18n('SCHEDULE_46') + '【', content.targetContent, '】'].join('');
                                                } else if (log.target == 'schedule.label.description') {
                                                    msg = content.sourceContent ? [rk.i18n('SCHEDULE_47') + '【', content.sourceContent, '】' + rk.i18n('SCHEDULE_46') + '【', content.targetContent, '】'].join('') : [rk.i18n('SCHEDULE_53') + '【', content.targetContent, '】'].join('');
                                                } else if (log.target == 'schedule.label.start.date') {
                                                    msg = [rk.i18n('SCHEDULE_48') + '【', Globalize.format(new Date(content.sourceContent - 0), 'yyyy-MM-dd HH:mm'), '】' + rk.i18n('SCHEDULE_46') + '【', Globalize.format(new Date(content.targetContent - 0), 'yyyy-MM-dd HH:mm'), '】'].join('');
                                                } else if (log.target == 'schedule.label.end.date') {
                                                    msg = [rk.i18n('SCHEDULE_49') + '【', Globalize.format(new Date(content.sourceContent - 0), 'yyyy-MM-dd HH:mm'), '】' + rk.i18n('SCHEDULE_46') + '【', Globalize.format(new Date(content.targetContent - 0), 'yyyy-MM-dd HH:mm'), '】'].join('');
                                                }
                                                break;
                                            case 4:
                                                //ACCEPT
                                                msg = rk.i18n('SCHEDULE_50');
                                                break;
                                            case 5:
                                                //REJECT
                                                msg = [rk.i18n('SCHEDULE_REJECT_THIS_REASON') + '“', content.reason, '”'].join('');
                                                break;
                                            case 7:
                                                //TRANSFER
                                                msg = [rk.i18n('SCHEDULE_51'), data.entity].join('');
                                                break;
                                            case 8:
                                                //ADD
                                                msg = [rk.i18n('TASK_TEXT_ADD_MEMBER'), $.map(content.addList, function(p) {
                                                    return '<a href="javascript:;">' + data.users[p].name + '</a>';
                                                }).join('、')].join('');
                                                break;
                                            case 9:
                                                //REMOVE
                                                msg = [rk.i18n('TASK_TEXT_REMOVE_MEMBER'), $.map(content.deleteList, function(p) {
                                                    return '<a href="javascript:;">' + data.users[p].name + '</a>';
                                                }).join('、')].join('');
                                                break;
                                        }
                                        return ['<div class="comment_content clear"><img class="userlogo" src="', opicon, '"><div class="right_comment"><div class="comment_word"><span><a href="/final/user.action?uid=', opid, '" class="username">', opname, '</a></span><span>', msg, '</span></div><div class="show_tool"><a class="publish_time">', Globalize.format(new Date(log.createAt - 0), 'yyyy-MM-dd HH:mm'), '</a></div></div></div>'].join('');
                                    }).join('');
                                    $panel.html(html);
                                } else {
                                    $panel.html('<div class="comment_content clear"><span>' + rk.i18n('SCHEDULE_52') + '</span></div>');
                                }
                            }).fail(function(def, code, message) {
                                def.status != 0 && $.msg(rk.i18n('REQUEST_ERROR'));
                            });
                        }
                        $tab.data('inited', true);
                    }
                }
            });
            $liTabs.eq(0).trigger('click');
        },
        appendNimei: function($panel, file) {
            var me = this,
                elem = this.element,
                opt = this.options;
            if (file.fileType == 0) {
                var fileClass = '';
                var img = '';

                if (file.swf) {
                    if (file.swf == "CONVERT_FAILED") {
                        file.preview = '<div class="file_class"><img src="/static/img/preview_fail.png"></div>';
                    } else {
                        file.preview = ['<div class="file_class js-file-previewable" filename="' + file.name + '" swfpath="' + file.swf + '"><img src="', '"></div>'].join(file.img);
                    }
                } else {
                    file.preview = '<div class="file_class file_nopreview"></div>';
                }
                $panel.find('div.js-upd-queue').after($.format('<div class="detail_attachment show_file clear">{#preview}<div class="file_info clear"><span class="name">{name}</span><span class="download"><a href="/common-file-download.action?commonFileId={id}&tfcode={tfcode}">' + rk.i18n('DOWNLOAD') + '</a><a href="javascript:;" style="margin-left:10px;" fileid="{id}" act="delete">' + rk.i18n('DELETE') + '</a></span></div><div class="file_time"><span>{createdByName}</span><span>' + rk.i18n('SCRPT_TMPL_SNS_FEED_FILE_SNIP_1') + '</span><span>{createAtFmt}</span></div></div>', file));

            } else {
                me.appendImage($panel, file);
            }
        },
        appendFile: function($panel, file) {
            var me = this,
                elem = this.element,
                opt = this.options;
            var fileClass = '';
            var img = '';
            if (file.canPreview == 'true') {
                img = '<img src="/img/file_previewing.png">';
            } else {
                fileClass = 'file_nopreview';
            }
            $panel.find('div.js-upd-queue').after($.format('<div class="detail_attachment show_file clear"><div class="file_class ' + fileClass + '">' + img + '</div><div class="file_info clear"><span class="name">{name}</span><span class="download"><a href="/common-file-download.action?commonFileId={id}&tfcode={tfcode}">' + rk.i18n('DOWNLOAD') + '</a><a href="javascript:;" style="margin-left:10px;" fileid="{id}" act="delete">' + rk.i18n('DELETE') + '</a></span></div><div class="file_time"><span>{createdByName}</span><span>' + rk.i18n('SCRPT_TMPL_SNS_FEED_FILE_SNIP_1') + '</span><span>{createAtFmt}</span></div></div>', file));
        },
        appendImage: function($panel, file) {
            var me = this,
                elem = this.element,
                opt = this.options;
            //$panel.find('div.js-upd-queue').after($.format('<div class="detail_attachment show_file clear"><div class="file_class"><img preivewsrc="{url}" src="{pic}" onclick="previewImage(this);"></div><div class="file_info clear"><span class="name">{name}</span><span class="download"><a href="/common-file-download.action?commonFileId={id}&tfcode={tfcode}">下载</a><a href="javascript:;" style="margin-left:10px;" fileid="{id}" act="delete">删除</a></span></div><div class="file_time"><span>{createdByName}</span><span>上传于</span><span>{createAtFmt}</span></div></div>', file));
            $panel.find('div.js-upd-queue').after($.format('<div class="detail_attachment show_file clear"><div class="file_class"><img href="{pic}" lurl="{url}" surl="{url}" src="{pic}" class="js-album"></div><div class="file_info clear"><span class="name">{name}</span><span class="download"><a href="/common-file-download.action?commonFileId={id}&tfcode={tfcode}">' + rk.i18n('DOWNLOAD') + '</a><a href="javascript:;" style="margin-left:10px;" fileid="{id}" act="delete">' + rk.i18n('DELETE') + '</a></span></div><div class="file_time"><span>{createdByName}</span><span>' + rk.i18n('SCRPT_TMPL_SNS_FEED_FILE_SNIP_1') + '</span><span>{createAtFmt}</span></div></div>', file));
        }
    });

    return {
        init: function(rkContent, id) {
            rkContent.scheduleFinalCtrl({
                scheduleId: id
            });
        }
    }
});
